package ua.kyivenergo.cableLines.search;

import ua.kyivenergo.cableLines.data.GenericObject;

import java.util.List;

/**
 * Created by Alex Kebkalo (kebka@mail.ru) on 18.04.14.
 */
public class SearchSystem {
    List<GenericObject> searchObjects;

    public SearchSystem(List<GenericObject> searchObjects) {
        this.searchObjects = searchObjects;
    }

    public List<GenericObject> performSearch(String searchString) {
        ResultsList results = new ResultsList();
        if ((searchString == null) || searchString.isEmpty()) {
            return searchObjects;
        }
        for (GenericObject currentObject : searchObjects) {
            double relevance = currentObject.getRelevance(searchString);
            if (relevance > 0) {
                results.addResult(currentObject, relevance);
            }
        }
        return results.getResults();
    }

}
